package com.gai.factory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

public class MyFactoryBean implements FactoryBean {
    /**
     * 获取对象实例返回出去
     * @return
     * @throws Exception
     */
    public Object getObject() throws Exception {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //创建链接
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/db_myschool1","gai","123456");
    }

    /**
     * 告知外部这个是什么样的类型数据
     * @return
     */
    public Class<?> getObjectType() {
        return Connection.class;
    }

    /**
     * 设置是否为单列
     * @return
     */
    public boolean isSingleton() {
        return false;
    }
}
